﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>商品详情</title>
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="keywords" content="销冠,TopSales微信" />
    <meta name="description" content="销冠,TopSales微信,TopSales销冠" />
    <base href="http://static.tops001.com/pointstore/" />
    <link href="css/main.css" rel="stylesheet" type="text/css" />
    <script src="../jq-bs-art.js" type="text/javascript"></script>
    <script src="js/common.js"></script>
    <script src="../kk.js"></script>
    <style type="text/css">
        .fade_info {
            display: none;
            position: fixed;
            top: 50%;
            left: 10%;
            width: 80%;
            background: #fff;
            z-index: 999;
            text-align: center;
            border-radius: 5px;
            margin-top:-150px;
        }

        .fade_info_warp {
            padding: 20px 20px 0 20px;
        }

        .fade_info .info1 {
            width: 100%;
            line-height: 24px;
            font-size: 16px;
            color: #fb7e00;
            text-align: center;
            margin-bottom: 5px;
        }

        .fade_info .info2 {
            width: 100%;
            line-height: 18px;
            font-size: 14px;
            color: #808080;
            text-align: center;
            margin-bottom: 10px;
        }

        .pop_inp {
            border: 1px solid #bfbfbf;
            margin-bottom: 9px;
            border-radius: 3px;
        }

            .pop_inp input {
                width: 88%;
                height: 28px;
                line-height: 28px;
                padding: 0 6%;
                border: 0 none;
                font-size: 14px;
                color: #9a9a9a;
            }

            .pop_inp textarea {
                width: 88%;
                height: 48px;
                line-height: 24px;
                padding: 10px 6%;
                border: 0 none;
                font-size: 14px;
                color: #9a9a9a;
            }

        .credit_con {
            height: auto;
            color: #666666;
            font-size: 14px;
            background: url(/images/line_bg.png) repeat-x bottom;
            padding-bottom: 70px;
        }
    </style>

</head>
<body>
    <div class="lay100">
        <img class="credit_img" width="100%" alt="" />
        <div class="shop_top">
            <div class="shop_left"><a>积分&nbsp;</a><span class="shop_num F_PointNum"></span></div>
            <!--<div class="shop_right">限兑0次</div>-->
        </div>
        <div class="credit_con" style="background:none;">
            <div class="credit_txt">
                <strong>商品介绍</strong><br />
                <div id="F_Description"></div>
            </div>
            <div>
                <!--<img src="images/ad_in.png" alt="" width="100%" />-->
            </div>
        </div>
        <div class="btn_foot">
            <button class="btn_ok" onclick="toShow()">马上兑换</button>
            <button class="btn_canceal"></button>
            <input type="hidden" id="hidStatus" />
        </div>
        <div class="cover">
        </div>
        <div class="fade_sure">
            <div class="fade_top">
                <img src="images/icon_02.png" width="75" alt="" />
            </div>
            <div class="fade_price">-<span class="F_PointNum">0</span>&nbsp;&nbsp;确定要兑换?</div>
            <div class="fade_btn">
                <button class="fade_canceal" onclick="f_No()">取消</button>
                <button class="fade_ok" onclick="f_Buy()">确定</button>
            </div>
        </div>
        <div class="fade_okey">
            <div id="fade_top" class="fade_top" style="display: none;">
                <img src="images/icon_04.png" width="60" alt="" />
            </div>
            <div id="fade_top02" class="fade_top" style="display: none;">
                <img src="images/icon_08.png" width="60" alt="" />
            </div>
            <div class="fade_txt01" id="F_Status"></div>
            <div class="fade_txt02">
                <a>您可以在兑换记录内查看</a>
            </div>
            <div class="fade_btn">
                <button class="fade_ok" onclick=" f_Show() ">确定</button>
            </div>
        </div>
        <!--style="display:block;"-->
        <div class="fade_info">
            <div class="fade_info_warp">
                <div class="info1">恭喜您已成功兑换该奖品</div>
                <div class="info2">请填写以下信息</div>
                <input type="hidden" id="exchangeId" name="exchangeId" />
                <div class="pop_inp"><input type="text" id="consignee" placeholder="真实姓名(必填)" maxlength="5" /></div>
                <div class="pop_inp"><input type="text" id="mobile" placeholder="联系方式(必填)" maxlength="12"/></div>
                <div class="pop_inp"><input type="text" id="companyname" placeholder="经纪公司名称(必填)" maxlength="30" /></div>
                <div class="pop_inp" style="margin-bottom:0;"><textarea id="companyaddress" placeholder="经纪公司地址(必填)" maxlength="100"></textarea></div>
                <div class="fade_btn">
                    <button class="fade_ok" id="btnSubmitAddress" onclick="submitAddress()">提交</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var apiUrl = "http://"+window.location.host+"/";
        var jinzhi = 1;
        function toShow() {
            $(".cover").show();
            $(".fade_sure").show();
            jinzhi = 0;
        }
        function toSure() {
            $(".fade_sure").hide();
            $(".fade_info").hide();
            $(".fade_okey").show();
        }
        function showShipInfo() {
            $(".fade_sure").hide();
            $(".fade_info").show();
        }
        function f_No() {
            $(".cover").hide();
            $(".fade_sure").hide();
            $(".fade_okey").hide();
            jinzhi = 1;
        }
        //禁止滑动
        document.body.addEventListener('touchmove', function (event) {
            if (jinzhi == 0) {
                event.preventDefault();
            }
        }, false);
        $(function () {
            f_Show();
   
        });
        //商品状态判断
        function f_Show() {
            var cityName = kk.queryString("cityName");
            var brokerKid=kk.queryString("BrokerKid");
            kk.api.get(apiUrl + "/ProductShow/Get",
              {
                  productKid: GetUrlParam("ProductKid"),
                  brokerKid: brokerKid
              }, function (data) {
                  var str = data.F_Description;
                  restr = str.replace(/\r\n/g, "</br>");
                  //$("#productPic").attr("src", "http://192.168.1.85:1060" + data.Data.F_PicUrl)

                  //picSelect(data.Thumbs, data.F_PicUrl, "350_350");
                  $(".F_PointNum").text(data.F_PointNum);
                  $("#F_Description").html(restr);
                  $(".credit_img").attr("src", data.F_PicUrl);

                  f_Alert(data.F_ProductName, cityName, brokerKid);
                  //switch (data.F_ExchangeType) {
                  //    case 0:
                  //        if (data.F_UserExchangeNum != 0) {
                  //            $(".shop_right").text("限兑" + data.F_UserExchangeNum + "次");
                  //        } else {
                  //            $(".shop_right").text("");
                  //        }
                  //        break;
                  //    case 1:
                  //        if (data.F_UserExchangeNum != 0) {
                  //            $(".shop_right").text("每天限兑" + data.F_UserExchangeNum + "次");
                  //        } else {
                  //            $(".shop_right").text("");
                  //        }
                  //        break;
                  //}

                  //$(".btn_canceal").show().text("敬请期待");
                  //$(".btn_ok").hide();
                  f_Status(data.IsStutas, data.F_IsMeskill,data.F_BeginTime + " " + data.F_ExchangeBeginTime);
              });
            setTimeout(function () { $(".lay100").fadeIn(1000) }, 500);
            f_No();
        }
        function f_Status(status, isMeskill, exchangeBeginTime) {
            if (isMeskill) {//秒杀
                if (status <= 0) {
                    switch (status) /// 状态 -1、活动未开启 -2、超出活动时间范围-3、经纪人不存在  -4、积分不足
                        /// -5:库存不足 -6:超出用户兑换数量 -7:该商品当日兑换数量已满
                        /// -8:兑换时间有误 -9:未到商品兑换开始时间  -10:商品兑换时间已结束
                    {
                        case -1:
                            $(".btn_canceal").show().text("秒杀未开始,敬请等待");//活动未开启
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -2:
                            $(".btn_canceal").show().text("你已错过秒杀时间范围");//兑换规则时间范围
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -3:
                            $(".btn_canceal").show().text("该账号无效");
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -4:
                            $(".btn_canceal").show().text("您的积分不足");
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -5:
                            $(".btn_canceal").show().text("该商品已抢完");
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -6:
                            $(".btn_canceal").show().text("您已抢购");
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -7:
                            $(".btn_canceal").show().text("今日已抢完，请明天再来");
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -8:
                            $(".btn_canceal").show().text("秒杀时间已过");//时间有误
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                        case -9:
                            //$("#hidStatus").val("20");
                            //$(".btn_canceal").show().text(exchangeBeginTime);
                            //$(".btn_canceal").show().text("秒杀未开始");
                            //$(".btn_canceal").hide(exchangeBeginTime);
                            //setInterval(function () {
                            //    send60();
                            //}, 1000);
                            //$(".btn_ok").hide();
                            //$(".btn_canceal").show();
                            //countDown(exchangeBeginTime);
                            $(".btn_canceal").show().text("该商品秒杀尚未开始,敬请等待");
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                            break;
                        case -10:
                            $(".btn_canceal").show().text("该商品秒杀时间已过,敬请等待下一波");
                            $(".btn_ok").hide();
                            $("#hidStatus").val("0");
                            break;
                    }
                } else {
                    $(".btn_ok").show().text("立即抢购");
                    $(".btn_canceal").hide();
                }
            } else {
                if (status <= 0) {
                    switch (status) /// 状态 -1、活动未开启 -2、超出活动时间范围-3、经纪人不存在  -4、积分不足
                        /// -5:库存不足 -6:超出用户兑换数量 -7:该商品当日兑换数量已满
                        /// -8:兑换时间有误 -9:未到商品兑换开始时间  -10:商品兑换时间已结束
                    {
                        case -1:
                            $(".btn_canceal").show().text("活动未开启");
                            $(".btn_ok").hide();
                            break;
                        case -2:
                            $(".btn_canceal").show().text("超出活动时间范围");
                            $(".btn_ok").hide();
                            break;
                        case -3:
                            $(".btn_canceal").show().text("经纪人不存在");
                            $(".btn_ok").hide();
                            break;
                        case -4:
                            $(".btn_canceal").show().text("积分不足 ");
                            $(".btn_ok").hide();
                            break;
                        case -5:
                            $(".btn_canceal").show().text("商品已兑完");
                            $(".btn_ok").hide();
                            break;
                        case -6:
                            $(".btn_canceal").show().text("已兑换");
                            $(".btn_ok").hide();
                            break;
                        case -7:
                            $(".btn_canceal").show().text("商品已兑完");
                            $(".btn_ok").hide();
                            break;
                        case -8:
                            $(".btn_canceal").show().text("该商品未到兑换时间");
                            $(".btn_ok").hide();
                            break;
                        case -9:
                            $(".btn_canceal").show().text("未到商品兑换开始时间");
                            $(".btn_ok").hide();
                            break;
                        case -10:
                            $(".btn_canceal").show().text("商品兑换时间已结束");
                            $(".btn_ok").hide();
                            break;
                    }
                } else {
                    $(".btn_ok").show();
                    $(".btn_canceal").hide();
                }
            }
        }


        //倒计时
        //var time_s = 0;
        function send60() {
            var hidStatus = $("#hidStatus").val();
            if (hidStatus == 20) {
                var ary_time = $(".btn_canceal").html().split(':');
                var time_m = 0;
                var time_s = 0;

                //取到HTML里的分，秒。再加
                if (ary_time.length == 2) {
                    time_m = parseInt(ary_time[0]);
                    time_s = parseInt(ary_time[1]);

                    //0秒停止
                    if (time_m == 0 && time_s == 0) {
                        $(".btn_ok").show().text("立即抢购");
                        $(".btn_canceal").hide();
                        return;
                    }
                    time_s = time_s - 1;
                }

                var NowTime = new Date(2014, 1, 1, 0, time_m, time_s, 0);
                var t = NowTime.getTime();
                var d = Math.floor(t / 1000 / 60 / 60 / 24);
                var h = Math.floor(t / 1000 / 60 / 60 % 24);
                var m = Math.floor(t / 1000 / 60 % 60);
                var s = Math.floor(t / 1000 % 60);
                $(".btn_canceal").text(pad(m, 2) + ":" + pad(s, 2));
            }
        }

        pad = function () {
            var tbl = [];
            return function (num, n) {
                var len = n - num.toString().length;
                if (len <= 0) return num;
                if (!tbl[len]) tbl[len] = (new Array(len + 1)).join('0');
                return tbl[len] + num;
            }
        }();



        function countDown(time) {
            //if(typeof end_time == "string")
            time = time.replace('-', '/');
            time = time.replace('-', '/');
            var end_time = new Date(time).getTime();//月份是实际月份-1
            //current_time = new Date().getTime(),
            sys_second = (end_time - new Date().getTime()) / 1000;
            var timer = setInterval(function () {
                if (sys_second > 0) {
                    sys_second -= 1;
                    var day = Math.floor((sys_second / 3600) / 24);
                    var hour = Math.floor((sys_second / 3600) % 24);
                    var minute = Math.floor((sys_second / 60) % 60);
                    var second = Math.floor(sys_second % 60);
                    //计算天
                  
                    hour < 10 ? "0" + hour : hour;//计算小时
                    minute < 10 ? "0" + minute : minute;//计算分
                    second < 10 ? "0" + second : second;// 计算秒
                    var showTime = "秒杀倒计时：";

                    if (day) {
                        showTime += day + "天";
                    }
                    if (hour) {
                        showTime += hour + "时";
                    }
                    if (minute || hour || day) {
                        showTime += minute + "分";
                    } else {
                        showTime += minute + ":";
                    }
                    if (hour || minute) {
                        showTime += second+"秒";
                    } else {
                        showTime += second;
                    }
                    
                    $(".btn_canceal").text(showTime);
                } else {
                    clearInterval(timer);
                    $(".btn_ok").show().text("立即抢购");
                    $(".btn_canceal").hide();
                }
            }, 1000);
        }



        //购买商品
        function f_Buy() {
            kk.api.get(apiUrl + "/ProductShow/Buy",
              {
                  productKid: GetUrlParam("ProductKid"),
                  brokerKid: GetUrlParam("BrokerKid")
              }, function (data) {
                  //alert(JSON.stringify(data));
                  var strAlert;
                  function loop() {
                      $(".btn_ok").hide();
                      $("#fade_top02").show();
                      $(".fade_txt02").text(" ");
                      $(".btn_canceal").show().text(strAlert);
                  };
                  //alert(data.Data);
                  if (data <= 0) {
                      switch (data) {
                          case 0: strAlert = "兑换失败"; loop(); break;
                          case -1: strAlert = "活动未开启"; loop(); break;
                          case -2: strAlert = "超出活动时间范围"; loop(); break;
                          case -3: strAlert = "经纪人不存在"; loop(); break;
                          case -4: strAlert = "积分不足"; loop(); break;
                          case -5: strAlert = "商品已兑完"; loop(); break;
                          case -6: strAlert = "已兑换"; loop(); break;
                          case -7: strAlert = "商品已兑完"; loop(); break;
                          case -8: strAlert = "兑换时间有误"; loop(); break;
                          case -9: strAlert = "未到商品兑换开始时间"; loop(); break;
                          case -10: strAlert = "商品兑换时间已结束"; loop(); break;
                          default: $("#fade_top02").show();
                      }
                  }
                  else {
                      $("#fade_top").show();
                  }
                  $("#F_Status").html(strAlert);
                  $("#exchangeId").val(data.Data);
                  $("#exchangeId").val(data);
                  showShipInfo();
              });
            $(".fade_txt02 a").attr("href", apiUrl+"change_histroy.html?BrokerKid=" + GetUrlParam("BrokerKid"));
        }

        function submitAddress() {

            if ($.trim( $("#consignee").val()).length <= 0)
            {
                kk.alert("名称必填", "提示");
                return;
            }

            if ($.trim($("#mobile").val()).length <= 0) {
                kk.alert("电话必填","提示");
                return;
            }

            if ($.trim($("#companyname").val()).length <= 0) {
                kk.alert("公司名称必填", "提示");
                return;
            }

            if ($.trim($("#companyaddress").val()).length <= 0) {
                kk.alert("公司地址必填", "提示");
                return;
            }

            var requestParam = {
                exchangeId: $("#exchangeId").val(),
                consignee: $("#consignee").val(),
                mobile: $("#mobile").val(),
                companyname: $("#companyname").val(),
                companyaddress: $("#companyaddress").val()
            };
            $("#btnSubmitAddress").attr("disabled", "true");
            kk.api.get(apiUrl+"/ProductsExchange/ShipInfo", requestParam, function (data) {
                toSure();
                $("#btnSubmitAddress").removeAttr("disabled");
            });
        }

    </script>
    <!--<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>-->  
    <script type="text/javascript">
        //function f_Alert(title, cityName, brokerKid)
        //{
        //    var nowTime = new Date().toString("yyyy-MM-dd HH:mm:ss");
        //    var ip = "";//returnCitySN["cip"];
        //    var brfore_url = document.referrer;
        //    var url = location.href;
        //    var str = "{\"messagekey\":\"f566f401-7dfc-454d-b57a-00692c8289e7\",\"checkcode\":\"123456\",\"messagetype\":\"1\",\"topic\":\"CLUB:EMBEDD:QUEUE\",\"sendtime\":\"" + nowTime + "\",\"sender\":\"TmallEmbedd\",\"createtime\":\"" + nowTime + "\",\"messagecontent\":{\"user_id\":\"" + brokerKid + "\",\"sent_time\":\"" + nowTime + "\",\"url\":\"" + url + "\",\"ip\":\"" + ip + "\",\"tag\":\"" + title + "\",\"brfore_url\":\"" + brfore_url + "\",\"city_name\":\"" + cityName + "\"}}";
        //    kk.api.add("a", "http://218.244.130.242:8080/");
        //    kk.api.a.post("set/data", { data: str });
        //}
        function f_Alert(title, cityName, brokerKid) {
            var ip = '';//returnCitySN["cip"];
            var before_url = document.referrer;
            var url = location.href;
            var str = {
                url: url,
                beforeUrl: before_url,
                city: cityName,
                tag: title
            }
            kk.api.add("a", "http://" + window.location.host + "/");
            kk.api.a.post("ExternalVisit/VisitPointStore", str);
        }
    </script>
</body>
</html>
